home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / os / 4.2bsd / osinit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-18  |  3.6 KB  |  155 lines

  1. /***********************************************************
  2. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24. /* $XConsortium: osinit.c,v 1.28 89/12/18 15:41:25 rws Exp $ */
  25. #include "os.h"
  26. #include "opaque.h"
  27. #undef NULL
  28. #ifdef NDBM
  29. #include <ndbm.h>
  30. #else
  31. #include <dbm.h>
  32. #endif
  33. #undef NULL
  34. #include <stdio.h>
  35. #include "Xos.h"
  36. #ifndef MAXPATHLEN
  37. /*
  38.  * just to get MAXPATHLEN.  Define it elsewhere if you need to
  39.  * avoid these files.
  40.  */
  41. #include <sys/param.h>
  42. #endif
  43.  
  44. #ifndef SYSV
  45. #include <sys/resource.h>
  46. #endif
  47.  
  48. #ifndef ADMPATH
  49. #define ADMPATH "/usr/adm/X%smsgs"
  50. #endif
  51.  
  52. #ifdef NDBM
  53. DBM     *rgb_dbm = (DBM *)NULL;
  54. #else
  55. int    rgb_dbm = 0;
  56. #endif
  57. extern char *display;
  58. #ifndef SYSV
  59. int limitDataSpace = -1;
  60. int limitStackSpace = -1;
  61. #endif
  62.  
  63. OsInit()
  64. {
  65.     static Bool been_here = FALSE;
  66.     char fname[MAXPATHLEN];
  67.  
  68. #ifdef macII
  69.     set42sig();
  70. #endif
  71.  
  72.     /* hack test to decide where to log errors */
  73.  
  74.     if (!been_here) {
  75.     if (write (2, fname, 0)) 
  76.     {
  77.         long t; 
  78.         char *ctime();
  79.         FILE *err;
  80.         fclose(stdin);
  81.         fclose(stdout);
  82.         sprintf (fname, ADMPATH, display);
  83.         /*
  84.          * uses stdio to avoid os dependencies here,
  85.          * a real os would use
  86.           *  open (fname, O_WRONLY|O_APPEND|O_CREAT, 0666)
  87.          */
  88.         if (!(err = fopen (fname, "a+")))
  89.         err = fopen ("/dev/null", "w");
  90.         if (err && (fileno(err) != 2)) {
  91.         dup2 (fileno (err), 2);
  92.         fclose (err);
  93.         }
  94. #ifdef SYSV        /* yes, even though it is 4.2bsd.... */
  95.         {
  96.         static char buf[BUFSIZ];
  97.         setvbuf (stderr, buf, _IOLBF, BUFSIZ);
  98.         }
  99. #else
  100.         setlinebuf(stderr);
  101. #endif
  102.         time (&t);
  103.         fprintf (stderr, "start %s", ctime(&t));
  104.     }
  105.  
  106.     if (getpgrp (0) == 0)
  107.         setpgrp (0, getpid ());
  108.  
  109.  
  110. #ifndef SYSV
  111. #if !defined(AIXrt) && !defined(AIX386)
  112.     if (limitDataSpace >= 0)
  113.     {
  114.         struct rlimit    rlim;
  115.  
  116.         if (!getrlimit(RLIMIT_DATA, &rlim))
  117.         {
  118.         if ((limitDataSpace > 0) && (limitDataSpace < rlim.rlim_max))
  119.             rlim.rlim_cur = limitDataSpace;
  120.         else
  121.             rlim.rlim_cur = rlim.rlim_max;
  122.         (void)setrlimit(RLIMIT_DATA, &rlim);
  123.         }
  124.     }
  125.     if (limitStackSpace >= 0)
  126.     {
  127.         struct rlimit    rlim;
  128.  
  129.         if (!getrlimit(RLIMIT_STACK, &rlim))
  130.         {
  131.         if ((limitStackSpace > 0) && (limitStackSpace < rlim.rlim_max))
  132.             rlim.rlim_cur = limitStackSpace;
  133.         else
  134.             rlim.rlim_cur = rlim.rlim_max;
  135.         (void)setrlimit(RLIMIT_STACK, &rlim);
  136.         }
  137.     }
  138. #endif
  139. #endif
  140.     been_here = TRUE;
  141.     }
  142.  
  143.     if (!rgb_dbm)
  144.     {
  145. #ifdef NDBM
  146.     rgb_dbm = dbm_open(rgbPath, 0, 0);
  147. #else
  148.     if (dbminit(rgbPath) == 0)
  149.         rgb_dbm = 1;
  150. #endif
  151.     if (!rgb_dbm)
  152.         ErrorF( "Couldn't open RGB_DB '%s'\n", rgbPath );
  153.     }
  154. }
  155.